package com.alstudio.utils.android;

import android.os.Environment;
import android.os.StatFs;

import com.alstudio.utils.log.Mylog;

public class ALSdcardManager {

	/**
	 * 检测当前SD卡是否可用。
	 * 
	 * @return true表示当前有可用的SD卡
	 */
	public static boolean isExtStorageAvailable() {
		return Environment.MEDIA_MOUNTED.equals(Environment
				.getExternalStorageState());
	}

	public static String getExtStoragePath() {
		if (isExtStorageAvailable()) {
			return Environment.getExternalStorageDirectory().getAbsolutePath();
		}
		return null;
	}

	/**
	 * 获取SD卡可用空间
	 * @return
	 */
	public static long getAvailableStorage() {
		try {
			StatFs stat = new StatFs(getExtStoragePath());
			long avaliableSize = ((long) stat.getAvailableBlocks() * (long) stat
					.getBlockSize());
			Mylog.d("外部存储器可用空间 : " + avaliableSize);
			return avaliableSize;
		} catch (RuntimeException ex) {
			return 0;
		}
	}

}
